package com.jokins.admin.vue.gitlog.controller;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.jokins.admin.vue.gitlog.param.ApplyParam;
import com.jokins.admin.vue.gitlog.param.SaveApplyParam;
import com.jokins.admin.vue.gitlog.service.ApplyService;
import com.jokins.admin.vue.gitlog.vo.ApplyVo;
import com.jokins.common.util.ResultData;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/apply")
public class ApplyController {

    @Autowired
    ApplyService applyService;

    /**
     * 获取应用列表
     * @param param
     * @return
     */
    @GetMapping("/list")
    public ResultData getApplyList(ApplyParam param) {
        final Page<Object> page = PageHelper.startPage(param.getCurrentPage(), param.getPageSize(), true);
        List<ApplyVo> applyVoList= applyService.getApplyList(param);
        return ResultData.pageResponse(applyVoList, page.getTotal(), page.getPages(), page.getPageNum());
    }

    @PostMapping("/save")
    public ResultData saveApply(@RequestBody SaveApplyParam param) {
         applyService.saveApply(param);
         return new ResultData("success");
    }
}
